<template>
  <div>
    <van-nav-bar
      title="登录"
      left-text="返回"
      left-arrow
      @click-left="goBack"
    />
    <van-image
      round
      width="6rem"
      height="6rem"
      :src="require('@/assets/logo.png')"
    />

    <!-- <img src="@/assets/logo.png" alt="" /> -->
    <van-form>
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button
          round
          block
          type="info"
          native-type="submit"
          @click="onSubmit"
          >登录</van-button
        >
      </div>
      <div class="reg">
        <div @click="toRegister">没有账号？立即注册</div>
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  name: "Login",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    onSubmit() {
      this.axios
        .post(`${process.env.VUE_APP_BASE_URL}/user/login`, {
          params: {
            uname: this.username,
            upwd: this.password,
          },
        })
        .then((res) => {
          console.log(res);
        });
      /*console.log('submit', values);*/
      if (this.username == "123456" && this.password == "123456") {
        Toast.success("登录成功");
        this.$router.push("/UserCenter");
      } else if (this.username == "" && this.password == "") {
        Toast("请输入账号或密码");
      } else {
        Toast.fail("账号或密码错误");
      }
    },
    toRegister() {
      this.$router.push("/Register");
    },
  },
};
</script>

<style scoped>
.reg {
  font-size: 40px;
}
.title {
  /* border-radius: 15px; */
  size: 1px;
  height: 50px;
  line-height: 50px;
  background-color: #20a0ff;
  color: #fff;
  text-align: center;
}
</style>